﻿function get_project_ids() {
var project_ids = [];
var project_ids_map = {};
jQuery('tr[bid_placed_check=1]').each(function (i, e) {
project_ids_map[jQuery(e).attr('project_id')] = true;
});
for (id in project_ids_map) {
project_ids.push(id);
}
return project_ids;
}
var checked_project_ids = {};
function check_projects_bid_status() {
var project_ids = get_project_ids();
/* if there is no project, do not send ajax request */
if (project_ids.length == 0) {
return;
}
var needcheck_project_ids = [];
for(var i = 0; i < project_ids.length; i++) {
if (!checked_project_ids[project_ids[i]]) {
checked_project_ids[project_ids[i]] = -1;
needcheck_project_ids.push(project_ids[i]);
} else if (checked_project_ids[project_ids[i]] == -1) {
continue;
} else {
update_project_bid_status(checked_project_ids[project_ids[i]]);
}
}
if (needcheck_project_ids.length == 0) {
return;
}
jQuery.post('/ajax/bid/bid_placed_status.php', {
"projects": needcheck_project_ids
},
update_projects_bid_status,
'json'
);
}
function update_projects_bid_status(data) {
if (data && data.retval == 'success' && data.projects) {
for (var i = 0; i < data.projects.length; i++) {
checked_project_ids[data.projects[i].id] = data.projects[i];
update_project_bid_status(data.projects[i]);
}
}
}
function update_project_bid_status(project) {
jQuery('tr[bid_placed_check=1][project_id=' + project.id + ']').css('background-color', '#afe0b2').attr('title', 'You have bid ' + jQuery('<div />').html(project.symbol).text() + project.amount + ' ' + project.currency + ' on this project');
}
/* check if the user has already login */
if (getUserIdfromCookie && getUserIdfromCookie()) {
check_projects_bid_status();
} 